//
//  YXMainTabBar.swift
//  yanXiangWeiBo
//
//  Created by 颜祥 on 15/12/15.
//  Copyright © 2015年 yanxiang. All rights reserved.
//

import UIKit

class YXMainTabBar: UITabBar {

    // MARK: -布局子控件
    override func layoutSubviews()
    {
        super.layoutSubviews()
        //print("self.subViews:\(self.subviews)")
        let count = 5
        var btnX : CGFloat = 0
        let btnY : CGFloat = 0
        let btnW : CGFloat = self.frame.size.width / CGFloat(count)
        let btnH : CGFloat = self.frame.size.height
        
        var i = 0
        
        for view in self.subviews
        {
            //print("view:\(view)")
            if view.isKindOfClass(NSClassFromString("UITabBarButton")!)
            {
                if i == 2
                {
                    i = 3
                }
                
                btnX = btnW * CGFloat(i)
                
                view.frame = CGRectMake(btnX, btnY, btnW, btnH)
                i++
            }
        }
        
        plusButton.center = CGPointMake(self.frame.size.width * 0.5, self.frame.size.height * 0.5)
        
        
    }
    
    
    // MARK: -懒加载 中间的加号按钮
    lazy var plusButton: UIButton =
    {
        let btn = UIButton()
        // 设置图片
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        btn.sizeToFit()
        
        self.addSubview(btn)
        
        return btn
    }()
    

}
